package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    private LinearLayout ll;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ll = (LinearLayout) findViewById(R.id.ll);


        //1,动态添加
        FragmentManager supportFragmentManager = getSupportFragmentManager();

        //开启事务
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();

        TwoFragment twoFragment2 = new TwoFragment();
        fragmentTransaction.add(R.id.ll,twoFragment2);

//        fragmentTransaction.remove(twoFragment2);
//        fragmentTransaction.replace(R.id.ll,new OneFragment());
//
//        fragmentTransaction.hide(twoFragment2);//隐藏
//        fragmentTransaction.show(twoFragment2);//显示

        fragmentTransaction.commit();//提交


    }
}
